package com.rs.game.player.content;

import java.util.HashMap;
import java.util.Map;

import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.player.actions.Action;
import com.rs.game.player.actions.Cooking.Cookables;

/**
 * Add ashes on altar
 * @author Swirl
 *
 */

@SuppressWarnings("unused")
public class AshesOnAltar extends Action {
	
	public final String MESSAGE = "The gods are very pleased with your offerings.";
	
	public enum Ashes {
		IMPIOUS(new Item(20264, 1), 13.9),
		ACCURSED(new Item(20266, 1), 12.5),
		INFERNAL(new Item(20268, 1), 218.7);
	
		private static Map<Short, Ashes> ashes = new HashMap<Short, Ashes>();
	
		public static Ashes forId(short itemId) {
			return ashes.get(itemId);
		}
	
		static {
			for (Ashes ash: Ashes.values()) {
				ashes.put((short) ash.getAsh().getId(), ash);
			}
		}
	
		private Item item;
		private double xp;
	
		private Ashes(Item item, double xp) {
			this.item = item;
			this.xp = xp;
		}
		
		public Item getAsh() {
			return item;
		}
		
		public double getXP() {
			return xp;
		}
	}
		
	private Ashes ash;
	private int amount;
	private Item item;
	private WorldObject object;
	private Animation USING = new Animation(896);
	
	public AshesOnAltar(WorldObject object, Item item, int amount) {
		this.amount = amount;
		this.item = item;
		this.object = object;
	}
	
	public static Ashes isGood(Item item) {
		return Ashes.forId((short) item.getId());
	}
	
	public boolean start(Player player) {
		if((this.ash = Ashes.forId((short) item.getId())) == null) {
			return false;
		}
		player.faceObject(object);
		return true;
	}
	
	public boolean process(Player player) {
		if (!World.getRegion(object.getRegionId()).containsObject(
						object.getId(), object))
			return false;
		if (!player.getInventory().containsItem(item.getId(), 1)) {
			return false;
		}
		if (!player.getInventory().containsItem(ash.getAsh().getId(), 1)) {
			return false;
		}
		return true;
	}
	
	public int processWithDelay(Player player) {
			player.setNextAnimation(USING);
			player.getPackets().sendGraphics(new Graphics(624), object);
			player.getInventory().deleteItem(item.getId(), 1);
			player.getSkills().addXp(Skills.PRAYER, ash.getXP());
			player.getPackets().sendGameMessage(MESSAGE);
			player.getInventory().refresh();
			return 3;
	}

	public void stop(final Player player) {
		this.setActionDelay(player, 3);
	}
	
}